package Memmory;

public class Memmory {
    
    private Word[] memmory;
    
    private int blockCount;
    private int blockSize;
    
    
    public Memmory(int blockCount, int blockSize) {
        this.blockCount = blockCount;
        this.blockSize = blockSize;
        memmory = new Word[blockCount * blockSize];
        for (int i = 0; i < blockCount*blockSize; i++) {
            memmory[i] = new Word();
        }
    }
    
    public void putWord(Word word, int address) {
        memmory[address] = word;
    }
    
    public void putWord(Word word, int x, int y) {
        memmory[blockSize * x + y] = word;
        //System.out.println("cia nx: " + ((blockSize -1 ) * x + y));
    }
    
    public Word getWord(int x, int y) {
        return memmory[blockSize * x + y];
    }
    
    public Word getWord(int address) {
        return memmory[address];
    }
    
    public void viewMemory() {
        Word word;
        byte[] value;
        
        for (int i = 0; i < blockCount*blockSize; i++) {
            if (i % 16 == 0) {System.out.println("takelis" + i / 16);}
            word = memmory[i];
            value = word.getBytes();
            System.out.print(i + ": ");
            for (int j = 0; j < 4; j++) {
                System.out.print((value[j] & 0xFF) + " ");
            }
            System.out.println();
        }
    }
}
